package zhaotest;

import com.alibaba.fastjson.JSONObject;
import com.tencent.trustsql.sdk.TrustSDK;
import com.tencent.trustsql.sdk.algorithm.ECDSAAlgorithm;
import com.tencent.trustsql.sdk.bean.PairKey;
import com.tencent.trustsql.sdk.demo.command.Command;

public class GeneratePairKeyCommand implements Command {

	@Override
	public String execute(String... args) throws Exception {
		System.out.println("Generate a pair of public key and private key:");
		PairKey pairKey = TrustSDK.generatePairKey(true);
		return JSONObject.toJSONString(pairKey);
	}

	public static void main(String[] args) throws Exception {
		PairKey pairKey = TrustSDK.generatePairKey(true);
		System.out.println(JSONObject.toJSONString(pairKey));
        PairKey pairKey1 = TrustSDK.generatePairKey(false);
        System.out.println(JSONObject.toJSONString(pairKey1));
		String correctPubKey = ECDSAAlgorithm.generatePublicKey(pairKey.getPrivateKey().trim());
		if (pairKey.getPublicKey().trim().equals(correctPubKey)) {
			System.out.println(true);
		}


        boolean b = TrustSDK.checkPairKey("Z8c/WU9/b5pLfkYDXT0W2tfBldCQiISAYFoHZ1L8nHE=", "A7YeD2GWfuV6c7SNNMjXiLPBOz6fkWkAfOrF5gA9HBv3");
        boolean b1 = TrustSDK.checkPairKey("5kVnC53d1tc+pPILLBZ27q1eI74taKe5tRYmMPj1a2k=", "BKi5KYl1FN5s3aty4nQ1KCJAajBxhPVohAvNfqHbPqeGXTpu3gQb+wF1Uv/0o5ts0OGEUgsvIBI0LbMcJNhvNcQ=");
        System.out.println("b:"+b);
        System.out.println("b1:"+b1);

    }

}
